<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title>平台授权</title>
		<link rel="Stylesheet" type="text/css" href="css/authorize/common.css" />
		<link rel="Stylesheet" type="text/css" href="css/authorize/main.css" />
		<link rel="Stylesheet" type="text/css" href="css/authorize/blue.css" />
		<script src="<%=basePath%>js/plugin/jquery-1.8.0.min.js" ></script>
		<link rel="Stylesheet" type="text/css" href="<%= basePath%>js/plugin/altDialog/ui-dialog.css" />
		<script type="text/javascript" src="<%= basePath%>js/plugin/altDialog/dialog-plus.js"></script>
		
		<style>
			.tab-con {
				-moz-border-bottom-colors: none;
				-moz-border-left-colors: none;
				-moz-border-right-colors: none;
				-moz-border-top-colors: none;
				background-color: #EDF4FC;
				background-position: 0 -228px;
				border-color: #BCD7EE #BCD7EE -moz-use-text-color;
				border-image: none;
				border-style: solid solid none;
				border-width: 1px 1px;
				height: 34px;
				margin-bottom: 0px;
				padding: 4px 10px 0;
				white-space: nowrap;
			}
			ol, ul {
				list-style: none outside none;
			}

			.tab-con li {
				background: url("images/authorize/v_line.gif") no-repeat scroll right center rgba(0, 0, 0, 0);
				display: inline !important;
				margin-left: -2px;
				position: relative;
			}

			* {
				letter-spacing: normal;
				padding: 0;
			}

			.tab-con li.focus a, .tab-con li.focus a:hover {
				background-position: -369px -110px;
				color: #333B49;
				display: inline-block;
				font-weight: bold;
			}
			.tab-con li a {

				float: left;
				height: 34px;
				line-height: 34px;
				padding: 0 15px;
				position: relative;
			}
			.tab-con li a, .msg-tab li a, .btm-tab li a {

				text-decoration: none;
			}
			.aui_outer {
				width: 820px;
			}
			
			
			
			span.button-main{
				background:url("<%=basePath%>/images/authorize/button.gif") 100% 0 no-repeat !important;
			}
			span.button-main:hover{
				background-position:100% -50px  !important;
			}
			span.button-main span{
				background:url("<%=basePath%>/images/authorize/button.gif") 0 0 no-repeat !important;
			}
			span.button-main:hover span{
				background-position:0 -50px !important;
			}
						
		</style>

		<script language="javascript">
			var ebaystatus = 1;
			var amstatus = 1;
			$(function() {
				$("ul li").removeClass("focus");
				$("#"+${pageIndex}).parent().addClass("focus");
				loadpage(${pageIndex});
// 				$("#"+${pageIndex}).attr("disabled", true)

// 				$("ul li a").click(function(){
// 					$("ul li").removeClass("focus");
// 					$(this).parent().addClass("focus");
// 					loadpage($(this).attr("id"))
// 				})
			});
			function loadpage(index) {
				$(".pdiv").hide();
				if (index == 1) {
					$("#ebay").show();
				} else if (index == 2) {
					$("#amz").show();
				} else if (index == 3) {
					$("#smt").show();
				}
			}

			function closedlg() {
				closeWindow();
			}

			function ebaybtn() {
				if (ebaystatus == 1) {
					$("#ebaybutton").val("我已通过授权");
					ebaystatus = 2;
					var ebayUrl = encodeURI($("#ebayUrl").val());
					window.open(ebayUrl, "_blank")
				} else if (ebaystatus == 2) {
					ebaystatus = 1;
					//店铺
	              	var customerNo = encodeURI($("#ebayCustomerNo").val());
	              	//SessionId
	              	var ebaySessionId = encodeURI($("#ebaySessionId").val());
	              	//昵称
	              	var nickName = encodeURI($("#ebayNickName").val());
	              	var order_source = encodeURI($("#ebayOrderSource").val());
		            $.post("saveAuthorize.sc?customerNo="+customerNo
						+"&ebaySessionId="+ebaySessionId
						+"&nickName="+nickName
						+"&order_source="+order_source,
					function(resultValue)
					{
// 		            	JSON.parse(resultValue).result;
		          		var strValue =resultValue.result;
		                if (strValue == "success") {
		                	dialog({
	                    		width: 300,
	        					content: '<div style="color:#0F0;font-weight:bold;text-align:center">'+
	        					'授权成功！</div>',
	        					fixed:true
	        				}).show();
	                    	setTimeout(function () {
	                    		closeWindow(); 
	                    	}, 3000);
		                }else {
	                      	dialog({
	                      		 title:'消息',
	        					 content: '<div style="color:#F00;font-size:15;font-weight:bold;">'+
	        					'&nbsp;&nbsp;&nbsp;授权保存异常：'+strValue+'&nbsp;&nbsp;</div>',
	        					 fixed:true,
	        					 okValue: '确 定',
		        				 ok: function () {}
	        				}).show();
		                }
	          		},"json");
				}
			}
			
			function smtbtn() {
				var smtUrl = encodeURI($("#smtUrl").val());
				window.open(smtUrl, "_blank")
			}
			
			var ctxpath =  "${ctxpath}";
            $(".validate").blur(function(){
                if($(this).val().replace(/(^\s*)|(\s*$)/g, "") == ""){
                    $(this).next("span").text($(this).attr("msg"));
                }else{
                    $(this).next("span").text(" * ");
                }
            });
            
            function amazonbtn(){
            	if(amstatus == 1){
            		$("#amazonbutton").val("我已通过授权");
					amstatus = 2;
					var amUrl = encodeURI($("#amUrl").val());
					window.open(amUrl, "_blank")
            	}else if(amstatus == 2){
	                //店铺
	                var customerNo = encodeURI($("#amCustomerNo").val());
					//昵称
	                var nickName = encodeURI($("#amNickName").val());
					if(nickName.replace(/(^\s*)|(\s*$)/g, "") == ""){
	                	$("#amNickName").next("span").text($("#amNickName").attr("msg"));
	                	return;
	                }else{
	                	$("#amNickName").next("span").text(" * ");
	                }
	                //merchantId
	                var merchantId = encodeURI($("#merchantId").val());
	                if(merchantId.replace(/(^\s*)|(\s*$)/g, "") == ""){
	                	$("#merchantId").next("span").text($("#merchantId").attr("msg"));
	                	return;
	                }else{
	                	$("#merchantId").next("span").text(" * ");
	                }
	                //marketplaceId
	                var marketplaceId = encodeURI($("#marketplaceId").val());
					if(marketplaceId.replace(/(^\s*)|(\s*$)/g, "") == ""){
	                	$("#marketplaceId").next("span").text($("#marketplaceId").attr("msg"));
	                	return;
	                }else{
	                	$("#marketplaceId").next("span").text(" * ");
	                }
					var order_source = encodeURI($("#amOrderSource").val());
					$.post("saveAuthorize.sc?customerNo="+customerNo
							+"&merchantId="+merchantId
							+"&marketplaceId="+marketplaceId
							+"&order_source="+order_source
							+"&nickName="+nickName,
					function(resultValue)
					{	
	            		var strValue = resultValue.result;
	                    if (strValue == "success") {
	                    	dialog({
	                    		width: 300,
	        					content: '<div style="color:#0F0;font-weight:bold;text-align:center">'+
	        					'授权成功！</div>',
	        					fixed:true
	        				}).show();
	                    	setTimeout(function () {
	                    		closeWindow(); 
	                    	}, 3000);
	                    }
	                    else {
	                      	dialog({
	                      		 title:'消息',
	        					 content: '<div style="color:#F00;font-size:15;font-weight:bold;">'+
	        					'&nbsp;&nbsp;&nbsp;授权保存异常：'+strValue+'&nbsp;&nbsp;</div>',
	        					 fixed:true,
	        					 okValue: '确 定',
		        				 ok: function () {}
	        				}).show();
	                    }
	            	},"json");
            	}
            }
			
            //关闭浏览器
            function closeWindow(){
            	debugger;
            	var userAgent = navigator.userAgent;
				if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Presto") != -1) {
				    window.location.replace("about:blank");
				} else {
				    window.opener = null;
				    window.open("", "_self");
				    window.close();
				}
            }
		</script>
	</head>
	<body>
		<div style="margin-left: 240px;margin-top: 20px;">
			<!-- ebay 帐号授权 -->
			<div id="mainbody" style="margin-top:10px;margin-left: 30px; width:820px"   >
				<ul id="tabs" class="tab-con">
					<li class="focus">
						<a  id="1" style="" href="#1">eBay账号<b></b></a>	
					</li>
					<li class="" style="">
						<a id="2" href="#2">AM账号<b></b></a>
					</li>
					<li class="" style="disabled:true;">
						<a id="3" href="#3" disabled = "true">速卖通账号<b></b></a>
					</li>
				</ul>
			</div>
			<div class="pdiv" style="margin-top:5px;margin-left: 30px; width:860px" id="ebay">
				<div class="aui_outer">
					<table class="aui_border">
						<tbody>
							<tr>
								<td class="aui_nw"></td><td class="aui_n"></td><td class="aui_ne"></td>
							</tr>
							<tr>
								<td class="aui_w"></td><td class="aui_c">
								<div class="aui_inner">
									<table class="aui_dialog">
										<tbody>
											<tr>
												<td colspan="2" class="aui_header">
												<div class="aui_titleBar">
													<div style="cursor: move;" class="aui_title">
														eBay账号授权步骤
													</div><a class="aui_close" href="javascript:;">×</a>
												</div></td>
											</tr>
											<tr>
												<td style="display: none;" class="aui_icon">&nbsp;</td>
												<td style="width: auto; height: auto; visibility: visible;" class="aui_main">
												<div style="padding: 20px 25px;" class="aui_content">

													<table style="width: 760px">

														<tbody>
															<tr>
																<td>
																<div style="font-size:1.2em;">
																	<b> 第一步：点“开始关联”到eBay官方网站登录</b>
																</div>
																<div>
																	<img src="images/authorize/linkeBayAcc.gif">
																</div></td>
																<td style="vertical-align: top">
																<div style="font-size:1.2em;">
																	<b> 第二步：成功登录后，点"I agree"同意授权</b>
																</div>
																<div>
																	<img src="images/authorize/linkeBayAcc1.gif">
																</div></td>
															</tr>
															<tr>
																<td colspan="2">
																	<span class="button button-main" style="" id="btnConfirm">
																		<span>
																			<input value="开始绑定" id="ebaybutton" onClick="ebaybtn()" type="button">
																		</span>
																	</span>
																	<span class="button button-main">
																		<span>
																			<input value="取消" onClick="closedlg()" type="button">
																		</span>
																	</span>
																</td>
															</tr>
														</tbody>
													</table>

												</div></td>
											</tr>
											<tr>
												<td colspan="2" class="aui_footer"><div style="display: none;" class="aui_buttons"></div></td>
											</tr>
										</tbody>
									</table>
								</div></td><td class="aui_e"></td>
							</tr>
							<tr>
								<td class="aui_sw"></td><td class="aui_s"></td><td style="cursor: se-resize;" class="aui_se"></td>
							</tr>
						</tbody>
					</table>
				</div>
				<input type="text" id=ebayCustomerNo value="${ebayCustomerNo}" style="display: none"/>
				<input type="text" id=ebayNickName value="${ebayNickName}" style="display: none"/>
		      	<input type="text" id="ebaySessionId" value="${ebaySessionId}" style="display: none"/>
		      	<input type="text" id="ebayOrderSource" value="${ebayOrderSource}" style="display: none"/>
		      	<input type="text" id=ebayUrl value="${ebayUrl}" style="display: none"/>
			</div>
			<div  class="pdiv" style="margin-top:5px;margin-left: 30px; width:860px" id="amz">
				<div class="aui_outer">
					<table class="aui_border">
						<tbody>
							<tr>
								<td class="aui_nw"></td><td class="aui_n"></td><td class="aui_ne"></td>
							</tr>
							<tr>
								<td class="aui_w"></td><td class="aui_c">
								<div class="aui_inner">
									<table class="aui_dialog">
										<tbody>
											<tr>
												<td colspan="2" class="aui_header">
												<div class="aui_titleBar">
													<div style="cursor: move;" class="aui_title">
														Amazon账号
													</div><a class="aui_close" href="javascript:;">×</a>
												</div></td>
											</tr>
											<tr>
												<td style="display: none;" class="aui_icon">&nbsp;</td>
												<td style="width: auto; height: auto; visibility: visible;" class="aui_main">
												<div style="padding: 20px 25px;" class="aui_content">

													<table  style="width: 760px; border-collapse: separate; border-spacing: 10px;">
														<tbody>
															<tr>
																<td colspan="2">
																	<div style="font-size:1.1em;">
																		第一步：点击”开始绑定“访问Amazon官方指定卖家授权网址并登录
																	</div>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<div style="font-size:1.1em;">
																		第二步：登录后点击页面第二个选项&nbsp;“I want to use an application ...”
																	</div>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<div style="font-size:1.1em;">
																		第三步：在&nbsp;"Application Name"&nbsp;文本框中，输入 <span style="color: #ff0000" id="applicationName">${amAppName}</span>
																	</div>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<div style="font-size:1.1em;">
																		第四步：在&nbsp;"Application's Developer Account Number"&nbsp;文本框中，输入
																		<span id="applicationNum" style="color: #ff0000;">${amAppNum}</span>
																	</div>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<div style="font-size:1.1em;">
																		第五步：点击&nbsp;<img src="images/amazonnext.png">&nbsp;阅读Amazon MWS License勾选2个选项并点击&nbsp;<img src="images/amazonnext.png">
																	</div>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<div style="font-size:1.1em;">
																		第六步：复制  Merchant ID, Marketplace ID填入下面对应的文本框中
																	</div>
																</td>
															</tr>
															<tr>
																<td  colspan="2" style = "TEXT-ALIGN: left;POSITION: relative; FLOAT: left;font-size:1.1em;" >
																	卖家帐号昵称：
																	<span>
																		<input id="amNickName"   value="${amNickName}" type="text" style="width:300px;margin-left: 22px;" class="validate" msg="&nbsp;&nbsp;请输入账号昵称">
																		<span style="color: #ff0000;">*</span>
																	</span>
																</td>
															</tr>
															<tr>
																<td  colspan="2" style = "TEXT-ALIGN: left;POSITION: relative; FLOAT: left;font-size:1.1em;" >
																	Merchant ID：
																	<span>
																		<input id="merchantId"  value="" type="text" style="width:300px;margin-left: 23px;" class="validate" msg="&nbsp;&nbsp;请输入卖家编号">
																		<span style="color: #ff0000;">*</span>
																	</span>
																</td>
															</tr>
															<tr>
																<td  colspan="2" style = "TEXT-ALIGN: left;POSITION: relative; FLOAT: left;font-size:1.1em;" >
																	Marketplace ID：
																	<span>
																		<input id="marketplaceId"  value="" type="text" style="width:300px;margin-left: 8px;" class="validate" msg="&nbsp;&nbsp;请输入市场编号">
																		<span style="color: #ff0000;">*</span>
																	</span>
																</td>
															</tr>
															<tr>
																<td colspan="2" style = "TEXT-ALIGN: left;POSITION: relative; FLOAT: left;font-size:1.1em;" >
																	第七步：点击我已通过授权，授权完成！
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<span class="button button-main" style="" id="btnConfirm">
																		<span>
																			<input value="开始绑定" id = "amazonbutton" onClick="amazonbtn()" type="button">
																		</span>
																	</span>
																	<span class="button button-main">
																		<span>
																			<input value="取消" onClick="closedlg()" type="button">
																		</span>
																	</span>
																</td>
															</tr>
														</tbody>
													</table>
													<input type="text" id="amazonSite" style="display: none"/>
													<input type="text" id=amCustomerNo value="${amCustomerNo}" style="display: none"/>
													<input type="text" id=amOrderSource value="${amOrderSource}" style="display: none"/>
													<input type="text" id=amUrl value="${amUrl}" style="display: none"/>
												</div></td>
											</tr>
											<tr>
												<td colspan="2" class="aui_footer"><div style="display: none;" class="aui_buttons"></div></td>
											</tr>
										</tbody>
									</table>
								</div></td><td class="aui_e"></td>
							</tr>
							<tr>
								<td class="aui_sw"></td><td class="aui_s"></td><td style="cursor: se-resize;" class="aui_se"></td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>

			<div class="pdiv" style="margin-top:5px;margin-left: 30px; width:860px" id="smt">
				<div class="aui_outer">
					<table class="aui_border">
						<tbody>
							<tr>
								<td class="aui_nw"></td><td class="aui_n"></td><td class="aui_ne"></td>
							</tr>
							<tr>
								<td class="aui_w"></td><td class="aui_c">
								<div class="aui_inner">
									<table class="aui_dialog">
										<tbody>
											<tr>
												<td colspan="2" class="aui_header">
												<div class="aui_titleBar">
													<div style="cursor: move;" class="aui_title">
														smt账号授权
													</div><a class="aui_close" href="javascript:;">×</a>
												</div></td>
											</tr>
											<tr>
												<td style="display: none;" class="aui_icon">&nbsp;</td>
												<td style="width: auto; height: auto; visibility: visible;" class="aui_main">
												<div style="width: 820px;height: 40px;" class="tooldiv" >
													<table style="width: 820px; border-collapse: separate; border-spacing: 10px;">
														<tr>
															<td style = "TEXT-ALIGN: right; font-size:1.1em;">
																	店铺名称：
															</td>
															<td style = "TEXT-ALIGN: left;POSITION: relative; FLOAT: left;font-size:1.1em;" >
																<input name="txtAliasName"  id="txtAliasName" value="${smtNickName}" style="width: 300px;" disabled="disabled" type="text"/>
																<input type="text" id="smtUrl" value="${smtUrl}" style="display: none"/>
															</td>
														</tr>
													</table>
												</div>
												<div style="width: 200px; margin-left: 30px;">
													<span class="button button-main">
														<span>
															<input id="smtbtn" onclick="smtbtn()" type="button" value="开始授权"/>
														</span>
													</span>
													<span class="button button-main">
														<span>
															<input onclick="closedlg();" type="button" value="取消"/>
														</span>
													</span>
												</div>
												</td>
											</tr>
											<tr>
												<td colspan="2" class="aui_footer"><div style="display: none;" class="aui_buttons"></div></td>
											</tr>
										</tbody>
									</table>
								</div></td><td class="aui_e"></td>
							</tr>
							<tr>
								<td class="aui_sw"></td><td class="aui_s"></td><td style="cursor: se-resize;" class="aui_se"></td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</body>
</html>